package com.infoland.afanmall.model.xilie.adapter;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.model.fuPin.entity.FuPinGoodsResponse;
import com.infoland.afanmall.model.story.entity.StoryEntity;
import com.infoland.afanmall.model.xilie.entity.XiLieEntity;

import java.util.List;

public class XlGoodsAdapter extends BaseQuickAdapter<XiLieEntity.GoodsListBean,BaseViewHolder> {

    public XlGoodsAdapter(int layoutResId, @Nullable List<XiLieEntity.GoodsListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, XiLieEntity.GoodsListBean item) {
        //商品图片
        ToolsKit.setImgView(item.getF_url(), helper.getView(R.id.ys_pt_item_image));
        //商品名称
        helper.setText(R.id.ys_pt_item_txt_name, item.getG_name());
        //商品规格
        helper.setText(R.id.ys_pt_item_txt_content, "规格："+item.getPrice_name());
        //商品现价
        helper.setText(R.id.ys_pt_item_txt_price1, "￥"+item.getG_price());
        //商品原价
        helper.setText(R.id.ys_pt_item_txt_price2, "￥"+item.getG_origin_price());
        //商品点击事件：进入商品详情页面
        helper.getView(R.id.pt_item_layout).setOnClickListener(v -> {
            callBack.onClick(v, helper.getAdapterPosition(), item);
        });
    }

    //点击事件接口
    private XiLieGoodsCallBack callBack;

    public interface XiLieGoodsCallBack {
        void onClick(View v, int position, XiLieEntity.GoodsListBean item);
    }

    public void setCallBack(XiLieGoodsCallBack callBack) {
        this.callBack = callBack;
    }
}
